package cn.cvs.servlet;

import cn.cvs.pojo.Rent;
import cn.cvs.servive.RentServive;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/ListServlet")
public class ListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        PrintWriter out = response.getWriter();
        Integer currPage = 1;
        if (request.getParameter("currPage")!=null){
            currPage = Integer.parseInt(request.getParameter("currPage"));
        }
        Integer pageSize = 3;
        RentServive servive = new RentServive();
        List<Rent> list = servive.gitrendList(currPage,pageSize);

        request.setAttribute("list",list);
        request.setAttribute("currPage",currPage);
        request.getRequestDispatcher("index.jsp").forward(request,response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
